<!--
 * @Author: 赵成刚-运输单-到货信息
-->
<template>
  <u-modal
    v-model="arrivalinformationModalShow"
    :width="'650'"
    class="modal1"
    contentBg="transparent"
    :show-title="false"
    :showConfirmButton="false"
  >
    <view class="freightSettlement-modal-box freightSettlement-modal-one-box">
      <image class="topimg" :src="`${imgUrl}waybill/pingjia.png`" />
      <view class="d-flex j-c title">到货信息</view>
      <view class="freightSettlement-center-box">
        <u-form :model="form" ref="uForm" :label-width="250">
          <u-form-item
            prop="arrivePoundPhoto"
            label="收货磅单"
            class="form-item-box"
            required
          >
            <u-upload
              ref="uUpload"
              :action="actionUrl"
              :custom-btn="true"
              @on-success="success2"
              :show-progress="form.arrivePoundPhoto ? false : true"
              @on-error="testerror"
              @on-remove="remove2"
              max-count="1"
              :form-data="{
                bucketName: 'logistics-control-platform',
                folderName: 'dispatchPic',
              }"
              :header="{ accessToken: accessToken }"
              class="uUpload-box"
              :width="310"
              :height="190"
              :upload-text="'收货磅单'"
            >
              <view
                slot="addBtn"
                class="slot-btn"
                hover-class="slot-btn__hover"
                hover-stay-time="150"
              >
                <image class="slot-img" src="./../../../../static/end.png" />
              </view>
            </u-upload>
          </u-form-item>
        </u-form>
      </view>
      <view class="freightSettlement-btn">
        <u-button
          @click="arrivalinformationcancel"
          class="u-btn"
          :throttle-time="0"
          >取 消
        </u-button>
        <u-button
          type="primary"
          class="u-btn"
          @click="arrivalinformationconfirm"
          >确 定
        </u-button>
      </view>
    </view>
  </u-modal>
</template>
<script>
import httpEnum from './../../../../common/httpEnum.js'
import { imgUrl } from 'common/httpEnum'

export default {
  name: 'arrivalinformationPhotoModal',
  props: {
    arrivalinformationModalShow: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      imgUrl,
      actionUrl: httpEnum.baseUploadUrl + '/freight-business/file/upload',
      accessToken: uni.getStorageSync('userAccount'),

      maxSize: 2097152,
      form: {
        arrivePoundPhoto: '',
      },
    }
  },
  methods: {
    testerror(res, index, lists, name) {
      this.$api.msg('上传失败')
    },
    success(data, index, lists, name) {
      if (data.code == '0') {
        this.form.arrivePhoto = data.result.originUrl
      } else {
        setTimeout(() => {
          this.$api.msg(data.message)
        }, 200)
      }
    },
    remove() {
      this.form.arrivePhoto = ''
    },
    success2(data, index, lists, name) {
      if (data.code == '0') {
        this.form.arrivePoundPhoto = data.result.originUrl
      } else {
        setTimeout(() => {
          this.$api.msg(data.message)
        }, 200)
      }
    },
    remove2() {
      this.form.arrivePoundPhoto = ''
    },
    rulesFun(value, num = 3) {
      const fixedNum = /(^(?:\d+|\d{1,3})(?:\.\d{0,3})?$)/
      const integer = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/
      let tag = undefined
      if (!value) {
        this.$api.msg('请输入到货重量')
        tag = false
        return tag
      } else if (!integer.test(value) || value == '0' || value == 0) {
        this.$api.msg(`到货重量必须大于0`)
        tag = false
        return tag
      } else if (!fixedNum.test(value)) {
        this.$api.msg(`到货重量精确到小数点${num}位`)
        tag = false
        return tag
      } else {
        tag = true
        return tag
      }
    },
    //到货信息-确认
    arrivalinformationconfirm() {
      if (!this.form.arrivePoundPhoto) {
        this.$api.msg('请上传收货磅单')
      } else {
        this.$emit('confirm', this.form)
      }
    },
    //到货信息-取 消
    arrivalinformationcancel() {
      this.$emit('cancel', false)
    },
  },
}
</script>
<style lang="scss" scoped>
@import './modal.scss';
</style>
